package com.example.anliku.controller;

import com.alibaba.fastjson.JSON;
import com.example.anliku.entity.*;
import com.example.anliku.entity.teamBody.TeamMemberBody;
import com.example.anliku.entity.teamBody.TeamMemberReturnBody;
import com.example.anliku.service.TeamMemberNewService;
import com.example.anliku.service.TeamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Api(tags = "团队模块")
@RestController
@RequestMapping("/api/team")
public class TeamController {
    @Resource
    private TeamService teamService;
    @Resource
    private TeamMemberNewService teamMemberNewService;

    @ApiOperation(value="添加团队信息")
    @PostMapping("/add")
    public Message insertSelective(Team team){
        team.setTeamTime(new Date());
        team.setTeamFinalTime(new Date());
        team.setTeamState(0);
        return teamService.insertSelective(team);
    }

    @ApiOperation(value="删除团队信息1")
    @DeleteMapping("/delete")
    public Message deleteByPrimaryKey(int teamId){
        return teamService.deleteByPrimaryKey(teamId);
    }

    @ApiOperation(value="修改团队信息")
    @PostMapping("/update")
    public Message updateByPrimaryKeySelective(Team team){
        team.setTeamFinalTime(new Date());
        return teamService.updateByPrimaryKeySelective(team);
    }

    @ApiOperation(value="根据团队ID查找团队信息")
    @GetMapping("/select")
    public Message selectByPrimaryKey(int teamId){
        return teamService.selectByPrimaryKey(teamId);
    }

    @ApiOperation(value="查询所有团队信息")
    @GetMapping("/selectAll")
    public Message selectAll(){
        return teamService.selectAll();
    }

    @ApiOperation(value="根据团队id和团队成员ID添加团队成员")
    @PostMapping("/addmember")
    public Message insertTeamIdByTeamMemberId(int teamId,String teamMemberId){
        return teamService.insertTeamIdByTeamMemberId(teamId,teamMemberId);
    }

    @ApiOperation(value="根据团队ID和团队成员ID删除团队成员")
    @DeleteMapping("/deletemember")
    public Message deleteByTeamIdByTeamMemberId(int teamId,String teamMemberId){
        return teamService.deleteByTeamIdByTeamMemberId(teamId,teamMemberId);
    }

    @ApiOperation(value="查询团队内所有成员信息")
    @GetMapping("/selectMember")
    public Message selectMemberAll(){
        return teamService.selectMemberAll();
    }

    @ApiOperation(value="根据团队id返回该团队内所有成员信息")
    @GetMapping("/teamId/member")
    public Message selectMemberByTeamId(Integer teamId,@RequestParam Integer pageNum,@RequestParam Integer size){
        return teamService.selectMemberByTeamId(teamId,pageNum,size);
    }

    @ApiOperation(value="根据团队成员真实姓名返回团队信息")
    @GetMapping("/teamMemberId/team")
    public Message selectAllByTeamMemberUserRealname(String teamMemberUserRealname) {
        return teamService.selectAllByTeamMemberUserRealname(teamMemberUserRealname);
    }

    @ApiOperation(value="根据团队负责人id返回团队信息")
    @GetMapping("/teamMainId/team")
    public Message selectteamByteamMainId(String teamMainId){
        return teamService.selectteamByteamMainId(teamMainId);
    }

    @ApiOperation(value="根据teamId查询团队内所有成员信息")
    @GetMapping("/selectMember/teamId")
    public Message selectAllByTeamId(Integer teamId){
        return teamService.selectAllByTeamId(teamId);
    }

    @ApiOperation(value="根据对应团队主键删除成员")
    @DeleteMapping("/deleteMember")
     public Message deleteByPrimaryKey(Integer teamMemberNewId){
        return teamMemberNewService.deleteByPrimaryKey(teamMemberNewId);
    }

    @ApiOperation(value="批量添加成员")
    @PostMapping("/insertMember")
    public Message insertList (String list){
        List<TeamMemberNew> exampleClazzList = JSON.parseArray(list,TeamMemberNew.class);
        return teamMemberNewService.insertList(exampleClazzList);
    }

    @ApiOperation(value="批量添加成员(body)")
    @PostMapping("/insertMemberBody")
    public Message insertListBody (@RequestBody List<TeamMemberReturnBody> teamMemberBodyList){
        return teamMemberNewService.batchInsert(teamMemberBodyList);
    }

    @ApiOperation(value="根据userId查询信息")
    @GetMapping("/select/userId")
    public Message selectAllByTeamMemberNewUserId(String teamMemberNewUserId){
        return teamMemberNewService.selectAllByTeamMemberNewUserId(teamMemberNewUserId);
    }

    @ApiOperation(value="根据userId删除团队成员信息")
    @DeleteMapping("/delete/member")
    public Message deleteByTeamMemberNewUserId(String teamMemberNewUserId){
        return teamMemberNewService.deleteByTeamMemberNewUserId(teamMemberNewUserId);
    }

    @ApiOperation(value="添加团队成员信息")
    @PostMapping("/delete/member")
    public Message insertSelective(TeamMemberNew record){
        return teamMemberNewService.insertSelective(record);
    }
}
